<?php

namespace App\Service\common;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\WebSocketServer\Sender;

class webSocketServer
{

    /**
     * @Inject
     * @var Sender
     */
    protected Sender $sender;

    /**
     * 关闭
     * @param int $fd
     */
    public function close(int $fd)
    {
        go(function () use ($fd) {
            sleep(1);
            $this->sender->disconnect($fd);
        });

        return '';
    }

    /**
     * 发送数据
     * @param int $fd
     * @param string $result
     */
    public function send(int $fd, string $result)
    {
        $res = $this->sender->push($fd, $result);
        var_dump('-------------------------------------发送send结果' . $result);
        return '';
    }
}